package nid.ui.controls.datePicker 
{
	import flash.display.GradientType;
	import flash.display.InterpolationMethod;
	import flash.display.Shape;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import nid.ui.controls.Button;
	
	/**
	 * ...
	 * @author Nidin P Vinayakan
	 */
	public class YearChanger extends Sprite 
	{
		private var bg:Shape;
		private var monthlist:MonthList;
		private var yearlist:YearList;
		private var _ok:Button;
		private var _cancel:Button;
		public var currentDateLabel:TextField;
		private var format:TextFormat;
		private var backgroundColor:Array;
		private var backgroundStrokeColor:uint;
		
		public function YearChanger(bgc:Array,bgsc:uint) 
		{
			backgroundColor = bgc;
			backgroundStrokeColor = bgsc;
			this.name = "YearChanger";
			this.mouseChildren = false;
			this.buttonMode = true;
			configUI();
		}
		
		private function configUI():void 
		{
			bg = new Shape();
			var type					:String 	= 	GradientType.RADIAL;
			var colorArray				:Array 		= 	backgroundColor;	
			var alphaArray				:Array 		=	[1,1];					
			var ratioArray				:Array		=	[0, 255];				
			var colorMatrix				:Matrix		=	new Matrix();			
			var spreadMethod			:String 	= 	SpreadMethod.PAD;		
			var interpolationMethod		:String		=	InterpolationMethod.LINEAR_RGB;
			var focalPointRatio			:Number		=	0;
			var bgStrokeColor			:int		=	backgroundStrokeColor;
			var bgStrokeThickness		:Number		=	1;
			var bgWidth					:Number		=	100;
			var bgHeight				:Number		=	100;
			
			colorMatrix.createGradientBox(bgWidth,bgHeight,0,0,0);
			
			bg.name 	= 	"background";
			
			bg.graphics.beginGradientFill(
			  type,
			  colorArray,
			  alphaArray,
			  ratioArray,
			  colorMatrix,
			  spreadMethod,
			  interpolationMethod,
			  focalPointRatio
			  );
			  
			bg.graphics.drawRect(0,0,bgWidth-2,bgHeight-2);
			bg.graphics.endFill();
			bg.x = 1;
			bg.y = 1;
			
			currentDateLabel		 		= 	new TextField();
			currentDateLabel.name 			= 	"currentDateLabel";
			//currentDateLabel.autoSize		=	TextFieldAutoSize.CENTER;
			currentDateLabel.selectable 	=	false;
			currentDateLabel.width			=	122;
			currentDateLabel.y				=	3;

			format 			= 	new TextFormat();
			format.font		=	"Tahoma";
			format.color	=	0x000000;
			format.size		=	12;
			format.bold		=	true;
			format.align	=	"center";
			
			currentDateLabel.defaultTextFormat	=	format;
			currentDateLabel.text				=	"";
			
			addChild(currentDateLabel);
			
			yearlist = new YearList();
			monthlist = new MonthList();
			
			_ok = new Button("OK", 40);
			_ok.name = "Button_1";
			_ok.x = 33;
			_ok.y = 181;
			_ok.addEventListener(MouseEvent.CLICK, close);			
			
			_cancel = new Button("CANCEL");
			_cancel.name = "Button_2";
			_cancel.x = 75;
			_cancel.y = 181;
			_cancel.addEventListener(MouseEvent.CLICK, close);
		}
		
		private function close(e:MouseEvent):void 
		{
			this.mouseChildren = false;
			this.buttonMode = true;
			this.x 	=	22;
			this.y 	=	3;
			currentDateLabel.x = 0;
			currentDateLabel.y = 3;
			removeChild(bg);
			removeChild(yearlist);
			removeChild(monthlist);
			removeChild(_ok);
			removeChild(_cancel);
		}
		
		override public function set width(value:Number):void 
		{
			bg.width = value-2;
		}
		override public function set height(value:Number):void 
		{
			bg.height = value-2;
		}
		public function popup():void
		{
			addChild(bg);
			addChild(yearlist);
			addChild(monthlist);
			addChild(_ok);
			addChild(_cancel);
			//addChild(currentDateLabel);
			currentDateLabel.x = 22;
			currentDateLabel.y = 6;
			this.mouseChildren = true;
			this.buttonMode = false;
		}
		public function popdown():void
		{
			removeChild(yearlist);
			removeChild(monthlist);
		}
		
	}

}